package cn.edu.zafu.bigdata.x.Yum;

import java.sql.SQLOutput;
import java.util.Random;
import java.util.Scanner;

public class GuessNumberGame {
    private static final Random random = new Random();
    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        /**
         * 生成一个1到100的随机数
         */
        int numToGuess = random.nextInt(100)+1;
        int maxTries = 10; //玩家最多可以猜的次数
        System.out.println("猜数字游戏开始！我已经想好一个1到100之间的数字。你有"+maxTries+"次机会猜它。");

        for (int tries=1; tries <= maxTries; tries++){
            System.out.println("请输入你的猜测（1-100）:");
            int guess = scanner.nextInt();

            if (guess == numToGuess) {
                System.out.println("恭喜你在第"+tries+"次猜对了数字是："+numToGuess);
                break;
            } else if (guess < numToGuess) {
                System.out.println("太小了，请再试一次！");
            }else {
                System.out.println("太大了，请再试一次！");
            }

            if (tries == maxTries){
                System.out.println("很遗憾，你的猜测字数用完了。正确的数字是："+numToGuess);
            }
        }

        System.out.println("你想再玩一次吗？(yes/no)：");
        String playagain = scanner.next();
        if (playagain.equalsIgnoreCase("yes")){
            main(args);
        }else{
            System.out.println("感谢你玩猜数字游戏，再见！");
        }
    }
}
